package com.nowcoder.Offer.Array;


import org.junit.Test;

/**
 * 二维数组中查找数字
 */
public class FindNumInMatrix {
    public boolean Find(int target, int [][] array) {
        int n = array.length;//行
        int m = array[0].length;//列
        int i = 0;
        int j = m - 1;
        while(i<n  && j >= 0){
            if(array[i][j] < target)
                i++;//往下找
            else if(array[i][j] > target)
                j--;//往左找
            else
                return true;
        }
        return false;

    }

    @Test
    public void test(){
        int[][] arr = {
                {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12},
                {13,14,15,16}
        };

        System.out.println(Find(5,arr));
        System.out.println(Find(100,arr));
    }
}
